﻿using netDxf;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Tables;
using System;
using System.Collections.Generic;

namespace TestDxfDocument
{

    class _Modulartaperinterfacewithballtracksystem
    {
        public static void Modulartaperinterfacewithballtracksystem(Dictionary<string, Object> data)//细柄丝锥
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            refin.Linetype = Linetype.Dashed;
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            centre.Linetype = Linetype.DashDot;
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            //参数
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);



            double scale = 1; //放大系数

            double dc = Convert.ToDouble(data["dc"]) * scale;
            double b1 = Convert.ToDouble(data["b1"]) * scale;
            double b2 = Convert.ToDouble(data["b2"]) * scale;
            double b3 = Convert.ToDouble(data["b3"]) * scale;
            double b4 = Convert.ToDouble(data["b4"]) * scale;
            double d1 = Convert.ToDouble(data["d1"]) * scale;
            double d2 = Convert.ToDouble(data["d2"]) * scale;
            double d3 = Convert.ToDouble(data["d3"]) * scale;
            double d4 = Convert.ToDouble(data["d4"]) * scale;
            double d5 = Convert.ToDouble(data["d5"]) * scale;
            double d6 = Convert.ToDouble(data["d6"]) * scale;
            double d7 = Convert.ToDouble(data["d7"]) * scale;
            double d8 = Convert.ToDouble(data["d8"]) * scale;
            double d9 = Convert.ToDouble(data["d9"]) * scale;
            double d10 = Convert.ToDouble(data["d10"]) * scale;
            double d11 = Convert.ToDouble(data["d11"]) * scale;
            double d12 = Convert.ToDouble(data["d12"]) * scale;
            double d13 = Convert.ToDouble(data["d13"]) * scale;
            double d14 = Convert.ToDouble(data["d14"]) * scale;
            double d15 = Convert.ToDouble(data["d15"]) * scale;
            double l1 = Convert.ToDouble(data["l1"]) * scale;
            double l2 = Convert.ToDouble(data["l2"]) * scale;
            double l3 = Convert.ToDouble(data["l3"]) * scale;
            double l4 = Convert.ToDouble(data["l4"]) * scale;
            double l5 = Convert.ToDouble(data["l5"]) * scale;
            double l6 = Convert.ToDouble(data["l6"]) * scale;
            double l7 = Convert.ToDouble(data["l7"]) * scale;
            double l8 = Convert.ToDouble(data["l8"]) * scale;
            double l9 = Convert.ToDouble(data["l9"]) * scale;
            double l10 = Convert.ToDouble(data["l10"]) * scale;
            double lll = Convert.ToDouble(data["l11"]) * scale;
            double l12 = Convert.ToDouble(data["l12"]) * scale;
            double l13 = Convert.ToDouble(data["l13"]) * scale;
            double l14 = Convert.ToDouble(data["l14"]) * scale;
            double l15 = Convert.ToDouble(data["l15"]) * scale;
            double l16 = Convert.ToDouble(data["l16"]) * scale;
            double l17 = Convert.ToDouble(data["l17"]) * scale;
            double l18 = Convert.ToDouble(data["l18"]) * scale;
            double l19 = Convert.ToDouble(data["l19"]) * scale;
            double l20 = Convert.ToDouble(data["l20"]) * scale;
            double l21 = Convert.ToDouble(data["l21"]) * scale;
            double l22 = Convert.ToDouble(data["l22"]) * scale;
            double l23 = Convert.ToDouble(data["l23"]) * scale;
            double l24 = Convert.ToDouble(data["l24"]) * scale;
            double l25 = Convert.ToDouble(data["l25"]) * scale;
            double r1 = Convert.ToDouble(data["r1"]) * scale;
            double r2 = Convert.ToDouble(data["r2"]) * scale;
            double r3 = Convert.ToDouble(data["r3"]) * scale;
            double r4 = Convert.ToDouble(data["r4"]) * scale;
            double r5 = Convert.ToDouble(data["r5"]) * scale;
            double t1 = Convert.ToDouble(data["t1"]) * scale;
            double t2 = Convert.ToDouble(data["t2"]) * scale;
            double t3 = Convert.ToDouble(data["t3"]) * scale;

            //坐标
            //1
            Vector2 v1 = new Vector2(0, 0);
            Vector2 v2 = new Vector2(v1.X - d3 / 2.44, v1.Y);
            Vector2 v3 = new Vector2(v1.X + dc - d3 / 2.44, v1.Y);
            Vector2 v4 = new Vector2(v1.X - dc / 2.85, v1.Y);
            Vector2 v5 = new Vector2(v4.X, v4.Y + d3 / 2); 
            Vector2 v6 = new Vector2(v1.X - l2 / 2 - 0.5, v5.Y);
            Vector2 v7 = new Vector2(v4.X, v4.Y - d3 / 2);
            Vector2 v8 = new Vector2(v6.X, v7.Y);
            Vector2 v9 = new Vector2(v1.X - l2 / 2, v8.Y + 1);
            Vector2 v10 = new Vector2(v1.X - l2 / 2, v6.Y - 0.6);
            Vector2 v11 = fun.Polar(v1, 117 * pi / 180, d8 / 2);
            Vector2 v12 = fun.Polar(v11, 134 * pi / 180, 0.5);
            Vector2 v13 = new Vector2(v12.X, v1.Y + d1 / 2 - 1);
            Vector2 v14 = new Vector2(v10.X, v1.Y + d1 / 2);
            Vector2 v15 = fun.Polar(v1, 113 * pi / 180, d8 / 2);
            Vector2 v16 = new Vector2(v15.X, v13.Y - 0.6);
            Vector2 v17 = fun.Polar(v16, -58 * pi / 180, d8 / 23.77);
            Vector2 v20 = fun.Polar(v1, 85 * pi / 180, d8 / 2);
            Vector2 v19 = new Vector2(v20.X, v16.Y - 0.3);
            Vector2 v21 = new Vector2(v20.X, v16.Y);
            Vector2 v18 = fun.Polar(v21, -122 * pi / 180, d8 / 23.77);
            Vector2 v24 = fun.Polar(v1, 77 * pi / 180, d8 / 2);
            Vector2 v23 = fun.Polar(v24, 58 * pi / 180, 0.4);
            Vector2 v22 = new Vector2(v23.X, v13.Y);
            Vector2 v25 = new Vector2(v1.X + d8 / 2 + 0.5, v14.Y);
            Vector2 v26 = new Vector2(v1.X + d8 / 2 + 0.5, v14.Y*-1);
            Vector2 v27 = fun.Polar(v1, -117 * pi / 180, d8 / 2);
            Vector2 v28 = fun.Polar(v27, -134 * pi / 180, 0.5);
            Vector2 v29 = new Vector2(v28.X, v16.Y * -1);
            Vector2 v30 = new Vector2(v14.X, v26.Y);
            Vector2 v31 = fun.Polar(v1, -113 * pi / 180, d8 / 2);
            Vector2 v32 = new Vector2(v31.X, v16.Y * -1);
            Vector2 v33 = new Vector2(v17.X, v17.Y * -1);
            Vector2 v38 = fun.Polar(v1, -85 * pi / 180, d8 / 2);
            Vector2 v39 = fun.Polar(v1, -77 * pi / 180, d8 / 2);
            Vector2 v40 = fun.Polar(v39, -58 * pi / 180, 0.4);
            Vector2 v35 = new Vector2(v38.X, v19.Y * -1);
            Vector2 v36 = new Vector2(v35.X, v21.Y * -1);
            Vector2 v34 = fun.Polar(v36, 122 * pi / 180, d8 / 23.77);
            Vector2 v37 = new Vector2(v40.X, v22.Y * -1);
            Vector2 v44 = new Vector2(v25.X, v1.Y + d2 / 2);
            Vector2 v41 = new Vector2(v25.X, v1.Y - d2 / 2);
            Vector2 v43 = new Vector2(v44.X + 0.5, v44.Y);
            Vector2 v42 = new Vector2(v41.X + 0.5, v41.Y);
            Vector2 v45 = fun.Polar(v43, -2.7 * pi / 180, l1 / 3 / Math.Cos(2.7 * pi / 180));
            Vector2 v46 = fun.Polar(v45, -2.7 * pi / 180, l1 / 3 / Math.Cos(2.7 * pi / 180));
            Vector2 v47 = fun.Polar(v46, -2.7 * pi / 180, (l1 / 3 - l5) / Math.Cos(2.7 * pi / 180));
            Vector2 v48 = fun.Polar(v47, -30 * pi / 180, l5 / Math.Cos(30 * pi / 180));
            Vector2 v50 = new Vector2(v47.X, v1.Y + d8 / 2);
            Vector2 v49 = new Vector2(v48.X, v50.Y + (l5 * Math.Tan(30 * pi / 180) / 2));
            Vector2 v51 = new Vector2(v25.X + l12, v50.Y);
            Vector2 v52 = new Vector2(v25.X + l8, v1.Y + d8 / 2 - 4.7);
            Vector2 v53 = new Vector2(v52.X, v1.Y - d8 / 2 + 4.7);
            Vector2 v54 = new Vector2(v51.X, v51.Y * -1);
            Vector2 v62 = new Vector2(v45.X, v45.Y * -1);
            Vector2 v61 = new Vector2(v46.X, v46.Y * -1);
            Vector2 v60 = new Vector2(v47.X, v47.Y * -1);
            Vector2 v59 = new Vector2(v48.X, v48.Y * -1);
            Vector2 v55 = new Vector2(v54.X + (v49.X - v51.X) / 2, v54.Y);
            Vector2 v56 = new Vector2(v55.X + (v49.X - v51.X) / 2 / 2.65, v55.Y - 0.6);
            Vector2 v57 = new Vector2(v60.X, v56.Y);
            Vector2 v58 = new Vector2(v59.X, v57.Y - +(l5 * Math.Tan(30 * pi / 180) / 2));

            //2
            Vector2 v111 = new Vector2(v1.X, v1.Y - d3 * 2);
            Vector2 v112 = new Vector2(v111.X - d3 / 2.44, v111.Y);
            Vector2 v113 = new Vector2(v3.X + (v1.X - v2.X), v111.Y);
            Vector2 v114 = new Vector2(v111.X - dc / 2.85, v111.Y);
            Vector2 v115 = new Vector2(v114.X, v114.Y + d3 / 2);
            Vector2 v63 = new Vector2(v111.X - l2 / 2 - 0.5, v115.Y);
            Vector2 v64 = new Vector2(v114.X, v114.Y - d3 / 2);
            Vector2 v65 = new Vector2(v111.X - l2 / 2 - 0.5, v64.Y);
            Vector2 v66 = new Vector2(v111.X - l2 / 2, v65.Y + 1);
            Vector2 v67 = new Vector2(v111.X - l2 / 2, v63.Y - 0.6);
            Vector2 v68 = new Vector2(v67.X, v111.Y + d1 / 2);
            Vector2 v71 = fun.Polar(v111, 117 * pi / 180, d8 / 2);
            Vector2 v70 = fun.Polar(v71, 134 * pi / 180, 0.5);
            Vector2 v69 = new Vector2(v70.X, v111.Y + d1 / 2 - 1);
            Vector2 v72 = fun.Polar(v111, 113 * pi / 180, d8 / 2);
            Vector2 v73 = new Vector2(v72.X, v69.Y - 0.6);
            Vector2 v74 = fun.Polar(v73, -58 * pi / 180, d8 / 23.77);
            Vector2 v77 = fun.Polar(v111, 85 * pi / 180, d8 / 2);
            Vector2 v76 = new Vector2(v77.X, v73.Y);
            Vector2 v75 = fun.Polar(v76, -122 * pi / 180, d8 / 23.77);
            Vector2 v80 = fun.Polar(v111, 77 * pi / 180, d8 / 2);
            Vector2 v79 = fun.Polar(v80, 58 * pi / 180, 0.4);
            Vector2 v78 = new Vector2(v79.X, v69.Y);
            Vector2 v95 = new Vector2(v111.X + d8 / 2 + 0.5, v68.Y);
            Vector2 v84 = fun.Polar(v111, -117 * pi / 180, d8 / 2);
            Vector2 v83 = fun.Polar(v84, -134 * pi / 180, 0.5);
            Vector2 v82 = new Vector2(v83.X, v111.Y - d1 / 2 + 1);
            Vector2 v81 = new Vector2(v66.X, v111.Y - d1 / 2);
            Vector2 v94 = new Vector2(v111.X + d8 / 2 + 0.5, v81.Y);
            Vector2 v85 = fun.Polar(v111, -113 * pi / 180, d8 / 2);
            Vector2 v86 = new Vector2(v85.X, v82.Y + 0.6);
            Vector2 v87 = fun.Polar(v86, 58 * pi / 180, d8 / 23.77);
            Vector2 v90 = fun.Polar(v111, -85 * pi / 180, d8 / 2);
            Vector2 v89 = new Vector2(v90.X, v86.Y);
            Vector2 v88 = fun.Polar(v89, 122 * pi / 180, d8 / 23.77);
            Vector2 v91 = fun.Polar(v111, -77 * pi / 180, d8 / 2);
            Vector2 v92 = fun.Polar(v91, -58 * pi / 180, 0.4);
            Vector2 v93 = new Vector2(v92.X, v82.Y);
            Vector2 v96 = new Vector2(v95.X, v111.Y + d2 / 2);
            Vector2 v97 = new Vector2(v96.X + 0.5, v96.Y);
            Vector2 v99 = new Vector2(v95.X, v111.Y - d2 / 2);
            Vector2 v98 = new Vector2(v99.X + 0.5, v99.Y);
            Vector2 v100 = fun.Polar(v97, -2.7 * pi / 180, l1 / 3 / Math.Cos(2.7 * pi / 180));
            Vector2 v108 = new Vector2(v95.X + l4, v111.Y);
            Vector2 v101 = new Vector2(v108.X, v100.Y - 0.5);
            Vector2 v102 = fun.Polar(v101, -2.7 * pi / 180, (l1 -l4 - l5) / Math.Cos(2.7 * pi / 180));
            Vector2 v103 = fun.Polar(v102, -30 * pi / 180, l5 / Math.Cos(30 * pi / 180));
            Vector2 v107 = fun.Polar(v98, 2.7 * pi / 180, l1 / 3 / Math.Cos(2.7 * pi / 180));
            Vector2 v106 = new Vector2(v108.X, v107.Y + 0.5);
            Vector2 v105 = fun.Polar(v106, 2.7 * pi / 180, (l1 - l4 - l5) / Math.Cos(2.7 * pi / 180));
            Vector2 v104 = fun.Polar(v105, 30 * pi / 180, l5 / Math.Cos(30 * pi / 180));
            Vector2 v109 = new Vector2(v108.X, v95.Y);
            Vector2 v110 = new Vector2(v108.X, v108.Y - d8 / 2 - 2);

            //3
            Vector2 v142 = fun.Polar(v1, 180 * pi / 180, d3 * 2);
            Vector2 v143 = fun.Polar(v142, -132 * pi / 180, d3 / 2 + 10);
            Vector2 v144 = fun.Polar(v142, 48 * pi / 180, d3 / 2 + 10);
            Vector2 v145 = fun.Polar(v142, 90 * pi / 180, d3 / 2 + 10);
            Vector2 v146 = fun.Polar(v142, -90 * pi / 180, d3 / 2 + 10);
            Vector2 v116 = new Vector2(v142.X - Math.Sqrt(Math.Pow(d10 / 2, 2) - Math.Pow(d8 / 2, 2)), v142.Y + (v50.Y - v1.Y));
            Vector2 v117 = new Vector2(v116.X - (Math.Sqrt((Math.Pow((v47.Y - v1.Y + 0.2), 2) - Math.Pow((v116.Y - v142.Y), 2))))-(v116.X - v142.X), v116.Y);
            Vector2 v119 = new Vector2(v116.X, v142.Y - (v116.Y - v142.Y));
            Vector2 v118 = new Vector2(v117.X, v142.Y - (v117.Y - v142.Y));
            Vector2 v121 = new Vector2(v142.X - Math.Sqrt(Math.Pow(d10/2,2) - Math.Pow(v1.Y - v57.Y,2)), v142.Y - (v1.Y - v57.Y));
            Vector2 v120 = new Vector2(v121.X - (Math.Sqrt(Math.Pow(v47.Y - v1.Y, 2) - Math.Pow(v1.Y - v57.Y,2)) - (v142.X - v121.X)), v121.Y);
            Vector2 v122 = new Vector2(v116.X - Math.Sqrt(Math.Pow(v47.Y - v1.Y,2 ) - Math.Pow(v116.Y - v142.Y,2)) - (v116.X - v142.X), v116.Y);
            Vector2 v123 = new Vector2(v116.X - Math.Sqrt(Math.Pow(v48.Y - v1.Y,2) - Math.Pow(v116.Y - v142.Y,2)) - (v116.X - v142.X), v116.Y);
            Vector2 v124 = new Vector2(v116.X - 2, v116.Y);
            Vector2 v125 = new Vector2(v116.X - 1, v116.Y);
            Vector2 v126 = new Vector2(v121.X - (Math.Sqrt(Math.Pow(v48.Y - v1.Y,2) - Math.Pow(v142.Y - v121.Y,2)) - (v142.X - v121.X)), v121.Y);
            Vector2 v127 = new Vector2(v121.X - 2, v121.Y);
            Vector2 v128 = new Vector2(v121.X - 1, v121.Y);
            Vector2 v129 = new Vector2(v142.X + (v142.X - v116.X), v116.Y);
            Vector2 v130 = new Vector2(v142.X + (v142.X - v117.X), v117.Y);
            Vector2 v131 = new Vector2(v142.X + (v142.X - v118.X), v118.Y);
            Vector2 v132 = new Vector2(v142.X + (v142.X - v119.X), v119.Y);
            Vector2 v133 = new Vector2(v142.X + (v142.X - v120.X), v120.Y);
            Vector2 v134 = new Vector2(v142.X + (v142.X - v121.X), v121.Y);
            Vector2 v135 = new Vector2(v142.X + (v142.X - v122.X), v122.Y);
            Vector2 v136 = new Vector2(v142.X + (v142.X - v123.X), v123.Y);
            Vector2 v137 = new Vector2(v142.X + (v142.X - v124.X), v124.Y);
            Vector2 v138 = new Vector2(v142.X + (v142.X - v125.X), v125.Y);
            Vector2 v139 = new Vector2(v142.X + (v142.X - v126.X), v126.Y);
            Vector2 v140 = new Vector2(v142.X + (v142.X - v127.X), v127.Y);
            Vector2 v141 = new Vector2(v142.X + (v142.X - v128.X), v128.Y);





            //作图
            //1
            Line line1 = new Line(v2, v3);
            line1.Layer = centre;
            line1.Linetype = Linetype.DashDot;
            line1.LinetypeScale = 3;
            dxf.AddEntity(line1);

            fun.drawcircle(dxf, v1, d8 / 2, 0.3, contour);

            fun.drawcircle(dxf, v1, d8 / 2 - 1, 0.3, contour);

            LwPolyline line2 = new LwPolyline();
            line2.Vertexes.Add(new LwPolylineVertex(v6));
            line2.Vertexes.Add(new LwPolylineVertex(v5));
            line2.Vertexes.Add(new LwPolylineVertex(v7));
            line2.Vertexes.Add(new LwPolylineVertex(v8));
            line2.Vertexes.Add(new LwPolylineVertex(v6));
            line2.Vertexes.Add(new LwPolylineVertex(v10));
            line2.Vertexes.Add(new LwPolylineVertex(v9));
            line2.Vertexes.Add(new LwPolylineVertex(v8));
            fun.PolyFill(dxf, line2, 0.3, contour);

            LwPolyline line3 = new LwPolyline();
            line3.Vertexes.Add(new LwPolylineVertex(v14));
            line3.Vertexes.Add(new LwPolylineVertex(v13));
            line3.Vertexes.Add(new LwPolylineVertex(v12));
            line3.Vertexes.Add(new LwPolylineVertex(v11));
            fun.PolyFill(dxf, line3, 0.3, contour);

            LwPolyline line5 = new LwPolyline();
            line5.Vertexes.Add(new LwPolylineVertex(v30));
            line5.Vertexes.Add(new LwPolylineVertex(v29));
            line5.Vertexes.Add(new LwPolylineVertex(v28));
            line5.Vertexes.Add(new LwPolylineVertex(v27));
            fun.PolyFill(dxf, line5, 0.3, contour);

            LwPolyline line6 = new LwPolyline();
            line6.Vertexes.Add(new LwPolylineVertex(v12));
            line6.Vertexes.Add(new LwPolylineVertex(v28));
            line6.Vertexes[0].Bulge = Math.Tan(125 * pi / 180 / 4);
            fun.PolyFill(dxf, line6, 0.3, contour);

            LwPolyline line7 = new LwPolyline();
            line7.Vertexes.Add(new LwPolylineVertex(v13));
            line7.Vertexes.Add(new LwPolylineVertex(v16));
            line7.Vertexes.Add(new LwPolylineVertex(v15));
            fun.PolyFill(dxf, line7, 0.3, contour);

            LwPolyline line8 = new LwPolyline();
            line8.Vertexes.Add(new LwPolylineVertex(v29));
            line8.Vertexes.Add(new LwPolylineVertex(v32));
            line8.Vertexes.Add(new LwPolylineVertex(v31));
            fun.PolyFill(dxf, line8, 0.3, contour);

            LwPolyline line9 = new LwPolyline();
            line9.Vertexes.Add(new LwPolylineVertex(v16));
            line9.Vertexes.Add(new LwPolylineVertex(v17));
            line9.Vertexes.Add(new LwPolylineVertex(v18));
            line9.Vertexes.Add(new LwPolylineVertex(v21));
            line9.Vertexes[0].Bulge = Math.Tan(19 * pi / 180 / 4);
            line9.Vertexes[1].Bulge = Math.Tan(99 * pi / 180 / 4);
            line9.Vertexes[2].Bulge = Math.Tan(19 * pi / 180 / 4);
            fun.PolyFill(dxf, line9, 0.3, contour);

            LwPolyline line10= new LwPolyline();
            line10.Vertexes.Add(new LwPolylineVertex(v32));
            line10.Vertexes.Add(new LwPolylineVertex(v33));
            line10.Vertexes.Add(new LwPolylineVertex(v34));
            line10.Vertexes.Add(new LwPolylineVertex(v36));
            line10.Vertexes[0].Bulge = Math.Tan(-19 * pi / 180 / 4);
            line10.Vertexes[1].Bulge = Math.Tan(-99 * pi / 180 / 4);
            line10.Vertexes[2].Bulge = Math.Tan(-19 * pi / 180 / 4);
            fun.PolyFill(dxf, line10, 0.3, contour);

            LwPolyline line11 = new LwPolyline();
            line11.Vertexes.Add(new LwPolylineVertex(v20));
            line11.Vertexes.Add(new LwPolylineVertex(v21));
            line11.Vertexes.Add(new LwPolylineVertex(v22));
            line11.Vertexes.Add(new LwPolylineVertex(v23));
            line11.Vertexes.Add(new LwPolylineVertex(v24));
            fun.PolyFill(dxf, line11, 0.3, contour);

            LwPolyline line12 = new LwPolyline();
            line12.Vertexes.Add(new LwPolylineVertex(v38));
            line12.Vertexes.Add(new LwPolylineVertex(v36));
            line12.Vertexes.Add(new LwPolylineVertex(v37));
            line12.Vertexes.Add(new LwPolylineVertex(v40));
            line12.Vertexes.Add(new LwPolylineVertex(v39));
            fun.PolyFill(dxf, line12, 0.3, contour);

            LwPolyline line13 = new LwPolyline();
            line13.Vertexes.Add(new LwPolylineVertex(v37));
            line13.Vertexes.Add(new LwPolylineVertex(v26));
            line13.Vertexes.Add(new LwPolylineVertex(v25));
            line13.Vertexes.Add(new LwPolylineVertex(v22));
            fun.PolyFill(dxf, line13, 0.3, contour);

            LwPolyline line14 = new LwPolyline();
            line14.Vertexes.Add(new LwPolylineVertex(v40));
            line14.Vertexes.Add(new LwPolylineVertex(v23));
            line14.Vertexes[0].Bulge = Math.Tan(153 * pi / 180 / 4);
            fun.PolyFill(dxf, line14, 0.3, contour);

            LwPolyline line15 = new LwPolyline();
            line15.Vertexes.Add(new LwPolylineVertex(v37));
            line15.Vertexes.Add(new LwPolylineVertex(v26));
            line15.Vertexes.Add(new LwPolylineVertex(v25));
            line15.Vertexes.Add(new LwPolylineVertex(v22));
            fun.PolyFill(dxf, line15, 0.3, contour);

            LwPolyline line16 = new LwPolyline();
            line16.Vertexes.Add(new LwPolylineVertex(v41));
            line16.Vertexes.Add(new LwPolylineVertex(v42));
            line16.Vertexes.Add(new LwPolylineVertex(v43));
            line16.Vertexes.Add(new LwPolylineVertex(v44));
            fun.PolyFill(dxf, line16, 0.3, contour);

            LwPolyline line17 = new LwPolyline();
            line17.Vertexes.Add(new LwPolylineVertex(v43));
            line17.Vertexes.Add(new LwPolylineVertex(v44));
            line17.Vertexes.Add(new LwPolylineVertex(v45));
            line17.Vertexes.Add(new LwPolylineVertex(v46));
            line17.Vertexes.Add(new LwPolylineVertex(v47));
            line17.Vertexes.Add(new LwPolylineVertex(v48));
            line17.Vertexes.Add(new LwPolylineVertex(v49));
            line17.Vertexes.Add(new LwPolylineVertex(v50));
            line17.Vertexes.Add(new LwPolylineVertex(v47));
            line17.Vertexes[2].Bulge = Math.Tan(42 * pi / 180 / 4);
            fun.PolyFill(dxf, line17, 0.3, contour);

            LwPolyline line18 = new LwPolyline();
            line18.Vertexes.Add(new LwPolylineVertex(v50));
            line18.Vertexes.Add(new LwPolylineVertex(v51));
            line18.Vertexes.Add(new LwPolylineVertex(v52));
            line18.Vertexes.Add(new LwPolylineVertex(v53));
            line18.Vertexes.Add(new LwPolylineVertex(v54));
            line18.Vertexes.Add(new LwPolylineVertex(v55));
            line18.Vertexes.Add(new LwPolylineVertex(v56));
            line18.Vertexes.Add(new LwPolylineVertex(v57));
            line18.Vertexes[1].Bulge = Math.Tan(88 * pi / 180 / 4);
            line18.Vertexes[3].Bulge = Math.Tan(88 * pi / 180 / 4);
            line18.Vertexes[5].Bulge = Math.Tan(71 * pi / 180 / 4);
            fun.PolyFill(dxf, line18, 0.3, contour);

            LwPolyline line19 = new LwPolyline();
            line19.Vertexes.Add(new LwPolylineVertex(v42));
            line19.Vertexes.Add(new LwPolylineVertex(v62));
            line19.Vertexes.Add(new LwPolylineVertex(v61));
            line19.Vertexes.Add(new LwPolylineVertex(v60));
            line19.Vertexes.Add(new LwPolylineVertex(v59));
            line19.Vertexes.Add(new LwPolylineVertex(v58));
            line19.Vertexes.Add(new LwPolylineVertex(v57));
            line19.Vertexes.Add(new LwPolylineVertex(v60));
            line19.Vertexes[1].Bulge = Math.Tan(-42 * pi / 180 / 4);
            fun.PolyFill(dxf, line19, 0.3, contour);

            //2
            Line line20 = new Line(v112, v113);
            line20.Layer = centre;
            line20.Linetype = Linetype.DashDot;
            line20.LinetypeScale = 3;
            dxf.AddEntity(line20);

            Line line21 = new Line(v109, v110);
            line21.Layer = centre;
            line21.Linetype = Linetype.DashDot;
            line21.LinetypeScale = 3;
            dxf.AddEntity(line21);

            fun.drawcircle(dxf, v111, d8 / 2, 0.3, contour);

            fun.drawcircle(dxf, v108, d8 / 2, 0.3, contour);

            LwPolyline line22 = new LwPolyline();
            line22.Vertexes.Add(new LwPolylineVertex(v63));
            line22.Vertexes.Add(new LwPolylineVertex(v115));
            line22.Vertexes.Add(new LwPolylineVertex(v64));
            line22.Vertexes.Add(new LwPolylineVertex(v65));
            line22.Vertexes.Add(new LwPolylineVertex(v63));
            line22.Vertexes.Add(new LwPolylineVertex(v67));
            line22.Vertexes.Add(new LwPolylineVertex(v66));
            line22.Vertexes.Add(new LwPolylineVertex(v65));
            fun.PolyFill(dxf, line22, 0.3, contour);

            LwPolyline line23 = new LwPolyline();
            line23.Vertexes.Add(new LwPolylineVertex(v68));
            line23.Vertexes.Add(new LwPolylineVertex(v69));
            line23.Vertexes.Add(new LwPolylineVertex(v70));
            line23.Vertexes.Add(new LwPolylineVertex(v71));
            fun.PolyFill(dxf, line23, 0.3, contour);

            LwPolyline line24 = new LwPolyline();
            line24.Vertexes.Add(new LwPolylineVertex(v81));
            line24.Vertexes.Add(new LwPolylineVertex(v82));
            line24.Vertexes.Add(new LwPolylineVertex(v83));
            line24.Vertexes.Add(new LwPolylineVertex(v84));
            fun.PolyFill(dxf, line24, 0.3, contour);

            LwPolyline line25 = new LwPolyline();
            line25.Vertexes.Add(new LwPolylineVertex(v70));
            line25.Vertexes.Add(new LwPolylineVertex(v83));
            line25.Vertexes[0].Bulge = Math.Tan(125 * pi / 180 / 4);
            fun.PolyFill(dxf, line25, 0.3, contour);

            LwPolyline line26 = new LwPolyline();
            line26.Vertexes.Add(new LwPolylineVertex(v69));
            line26.Vertexes.Add(new LwPolylineVertex(v73));
            line26.Vertexes.Add(new LwPolylineVertex(v72));
            fun.PolyFill(dxf, line26, 0.3, contour);

            LwPolyline line27 = new LwPolyline();
            line27.Vertexes.Add(new LwPolylineVertex(v82));
            line27.Vertexes.Add(new LwPolylineVertex(v86));
            line27.Vertexes.Add(new LwPolylineVertex(v85));
            fun.PolyFill(dxf, line27, 0.3, contour);

            LwPolyline line28 = new LwPolyline();
            line28.Vertexes.Add(new LwPolylineVertex(v73));
            line28.Vertexes.Add(new LwPolylineVertex(v74));
            line28.Vertexes.Add(new LwPolylineVertex(v75));
            line28.Vertexes.Add(new LwPolylineVertex(v76));
            line28.Vertexes[0].Bulge = Math.Tan(19 * pi / 180 / 4);
            line28.Vertexes[1].Bulge = Math.Tan(99 * pi / 180 / 4);
            line28.Vertexes[2].Bulge = Math.Tan(19 * pi / 180 / 4);
            fun.PolyFill(dxf, line28, 0.3, contour);

            LwPolyline line29 = new LwPolyline();
            line29.Vertexes.Add(new LwPolylineVertex(v86));
            line29.Vertexes.Add(new LwPolylineVertex(v87));
            line29.Vertexes.Add(new LwPolylineVertex(v88));
            line29.Vertexes.Add(new LwPolylineVertex(v89));
            line29.Vertexes[0].Bulge = Math.Tan(-19 * pi / 180 / 4);
            line29.Vertexes[1].Bulge = Math.Tan(-99 * pi / 180 / 4);
            line29.Vertexes[2].Bulge = Math.Tan(-19 * pi / 180 / 4);
            fun.PolyFill(dxf, line29, 0.3, contour);

            LwPolyline line30 = new LwPolyline();
            line30.Vertexes.Add(new LwPolylineVertex(v77));
            line30.Vertexes.Add(new LwPolylineVertex(v76));
            line30.Vertexes.Add(new LwPolylineVertex(v78));
            line30.Vertexes.Add(new LwPolylineVertex(v79));
            line30.Vertexes.Add(new LwPolylineVertex(v80));
            fun.PolyFill(dxf, line30, 0.3, contour);

            LwPolyline line31 = new LwPolyline();
            line31.Vertexes.Add(new LwPolylineVertex(v90));
            line31.Vertexes.Add(new LwPolylineVertex(v89));
            line31.Vertexes.Add(new LwPolylineVertex(v93));
            line31.Vertexes.Add(new LwPolylineVertex(v92));
            line31.Vertexes.Add(new LwPolylineVertex(v91));
            fun.PolyFill(dxf, line31, 0.3, contour);

            LwPolyline line32 = new LwPolyline();
            line32.Vertexes.Add(new LwPolylineVertex(v93));
            line32.Vertexes.Add(new LwPolylineVertex(v94));
            line32.Vertexes.Add(new LwPolylineVertex(v95));
            line32.Vertexes.Add(new LwPolylineVertex(v78));
            fun.PolyFill(dxf, line32, 0.3, contour);

            LwPolyline line33 = new LwPolyline();
            line33.Vertexes.Add(new LwPolylineVertex(v99));
            line33.Vertexes.Add(new LwPolylineVertex(v98));
            line33.Vertexes.Add(new LwPolylineVertex(v97));
            line33.Vertexes.Add(new LwPolylineVertex(v96));
            fun.PolyFill(dxf, line33, 0.3, contour);

            LwPolyline line34 = new LwPolyline();
            line34.Vertexes.Add(new LwPolylineVertex(v92));
            line34.Vertexes.Add(new LwPolylineVertex(v79));
            line34.Vertexes[0].Bulge = Math.Tan(153 * pi / 180 / 4);
            fun.PolyFill(dxf, line34, 0.3, contour);

            LwPolyline line35 = new LwPolyline();
            line35.Vertexes.Add(new LwPolylineVertex(v97));
            line35.Vertexes.Add(new LwPolylineVertex(v100));
            line35.Vertexes.Add(new LwPolylineVertex(v101));
            line35.Vertexes.Add(new LwPolylineVertex(v102));
            line35.Vertexes.Add(new LwPolylineVertex(v103));
            line35.Vertexes.Add(new LwPolylineVertex(v104));
            line35.Vertexes.Add(new LwPolylineVertex(v105));
            line35.Vertexes.Add(new LwPolylineVertex(v106));
            line35.Vertexes.Add(new LwPolylineVertex(v107));
            line35.Vertexes.Add(new LwPolylineVertex(v98));
            line35.Vertexes[1].Bulge = Math.Tan(34 * pi / 180 / 4);
            line35.Vertexes[7].Bulge = Math.Tan(34 * pi / 180 / 4);
            fun.PolyFill(dxf, line35, 0.3, contour);

            LwPolyline line36 = new LwPolyline();
            line36.Vertexes.Add(new LwPolylineVertex(v102));
            line36.Vertexes.Add(new LwPolylineVertex(v105));
            fun.PolyFill(dxf, line36, 0.3, contour);

            //3
            Line line37 = new Line(v143, v144);
            line37.Layer = centre;
            line37.Linetype = Linetype.DashDot;
            line37.LinetypeScale = 3;
            dxf.AddEntity(line37);

            Line line38 = new Line(v145, v146);
            line38.Layer = centre;
            line38.Linetype = Linetype.DashDot;
            line38.LinetypeScale = 3;
            dxf.AddEntity(line38);


            fun.drawcircle(dxf, v142, d3 / 2, 0.3, contour);

            fun.drawcircle(dxf, v142, (v10.Y - v1.Y), 0.3, contour);

            fun.drawcircle(dxf, v142, d1 / 2, 0.3, contour);

            fun.drawcircle(dxf, v142, d2 / 2, 0.3, contour);

            fun.drawcircle(dxf, v142, d7 / 2, 0.3, contour);

            fun.drawcircle(dxf, v142, d5 / 2, 0.3, contour);

            fun.drawcircle(dxf, v142, d10 / 2, 0.3, contour);

            fun.drawcircle(dxf, v142, d7 / 3, 0.3, contour);

            fun.drawcircle(dxf, v142, d1 / 2 + 0.5, 0.3, contour);

            LwPolyline line39 = new LwPolyline();
            line39.Vertexes.Add(new LwPolylineVertex(v116));
            line39.Vertexes.Add(new LwPolylineVertex(v117));
            line39.Vertexes.Add(new LwPolylineVertex(v118));
            line39.Vertexes.Add(new LwPolylineVertex(v119));
            line39.Vertexes[1].Bulge = Math.Tan(41 * pi / 180 / 4);
            fun.PolyFill(dxf, line39, 0.3, contour);

            LwPolyline line40 = new LwPolyline();
            line40.Vertexes.Add(new LwPolylineVertex(v121));
            line40.Vertexes.Add(new LwPolylineVertex(v120));
            line40.Vertexes.Add(new LwPolylineVertex(v118));
            fun.PolyFill(dxf, line40, 0.3, contour);


            LwPolyline line41 = new LwPolyline();
            line41.Vertexes.Add(new LwPolylineVertex(v129));
            line41.Vertexes.Add(new LwPolylineVertex(v130));
            line41.Vertexes.Add(new LwPolylineVertex(v131));
            line41.Vertexes.Add(new LwPolylineVertex(v132));
            line41.Vertexes[1].Bulge = Math.Tan(-41 * pi / 180 / 4);
            fun.PolyFill(dxf, line41, 0.3, contour);

            LwPolyline line42 = new LwPolyline();
            line42.Vertexes.Add(new LwPolylineVertex(v131));
            line42.Vertexes.Add(new LwPolylineVertex(v133));
            line42.Vertexes.Add(new LwPolylineVertex(v134));
            fun.PolyFill(dxf, line42, 0.3, contour);

            LwPolyline line43 = new LwPolyline();
            line43.Vertexes.Add(new LwPolylineVertex(v122));
            line43.Vertexes.Add(new LwPolylineVertex(v135));
            line43.Vertexes[0].Bulge = Math.Tan(-141 * pi / 180 / 4);
            fun.PolyFill(dxf, line43, 0.3, contour);

            LwPolyline line44 = new LwPolyline();
            line44.Vertexes.Add(new LwPolylineVertex(v123));
            line44.Vertexes.Add(new LwPolylineVertex(v136));
            line44.Vertexes[0].Bulge = Math.Tan(-136 * pi / 180 / 4);
            fun.PolyFill(dxf, line44, 0.3, contour);

            LwPolyline line45 = new LwPolyline();
            line45.Vertexes.Add(new LwPolylineVertex(v124));
            line45.Vertexes.Add(new LwPolylineVertex(v137));
            line45.Vertexes[0].Bulge = Math.Tan(-135 * pi / 180 / 4);
            fun.PolyFill(dxf, line45, 0.3, contour);

            LwPolyline line46 = new LwPolyline();
            line46.Vertexes.Add(new LwPolylineVertex(v125));
            line46.Vertexes.Add(new LwPolylineVertex(v138));
            line46.Vertexes[0].Bulge = Math.Tan(-136 * pi / 180 / 4);
            fun.PolyFill(dxf, line46, 0.3, contour);

            LwPolyline line47 = new LwPolyline();
            line47.Vertexes.Add(new LwPolylineVertex(v120));
            line47.Vertexes.Add(new LwPolylineVertex(v133));
            line47.Vertexes[0].Bulge = Math.Tan(140 * pi / 180 / 4);
            fun.PolyFill(dxf, line47, 0.3, contour);

            LwPolyline line48 = new LwPolyline();
            line48.Vertexes.Add(new LwPolylineVertex(v126));
            line48.Vertexes.Add(new LwPolylineVertex(v139));
            line48.Vertexes[0].Bulge = Math.Tan(135 * pi / 180 / 4);
            fun.PolyFill(dxf, line48, 0.3, contour);

            LwPolyline line49 = new LwPolyline();
            line49.Vertexes.Add(new LwPolylineVertex(v127));
            line49.Vertexes.Add(new LwPolylineVertex(v140));
            line49.Vertexes[0].Bulge = Math.Tan(132 * pi / 180 / 4);
            fun.PolyFill(dxf, line49, 0.3, contour);

            LwPolyline line50 = new LwPolyline();
            line50.Vertexes.Add(new LwPolylineVertex(v128));
            line50.Vertexes.Add(new LwPolylineVertex(v141));
            line50.Vertexes[0].Bulge = Math.Tan(132 * pi / 180 / 4);
            fun.PolyFill(dxf, line50, 0.3, contour);


            //标注样式
            //箭头样式
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 1;
            dimensionStyle.ExtLineExtend = 0.6;//标注延长线长度/2
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = 1;
            double offset = 10;


            //文本样式
            dimensionStyle.TextHeight = 2;

            LinearDimension dim1 = new LinearDimension(new Line(v10, v25), d8, 0, dimensionStyle);
            dim1.UserText = "l2=" + Math.Round(l2 * scale, 1);
            dxf.AddEntity(dim1);

            LinearDimension dim2 = new LinearDimension(new Line(v25, v52), d8 * 2, 0, dimensionStyle);
            dim2.UserText = "l8=" + Math.Round(l8 * scale, 1);
            dxf.AddEntity(dim2);

            LinearDimension dim3 = new LinearDimension(new Line(v25, v51), d8 + d8 * 3 / 2, 0, dimensionStyle);
            dim3.UserText = "l12=" + Math.Round(l12 * scale, 1);
            dxf.AddEntity(dim3);

            LinearDimension dim4 = new LinearDimension(new Line(v25, v48), d8 * 3, 0, dimensionStyle);
            dim4.UserText = "l1=" + Math.Round(l1 * scale, 1);
            dxf.AddEntity(dim4);

            LinearDimension dim5 = new LinearDimension(new Line(v47, v48), d8 * 2, 0, dimensionStyle);
            dim5.UserText = "l5=" + Math.Round(l5 * scale, 1);
            dxf.AddEntity(dim5);

            LinearDimension dim6 = new LinearDimension(new Line(v43, v42), d8 * 4, -90, dimensionStyle);
            dim6.UserText = "d2=" + Math.Round(d2 * scale, 1);
            dxf.AddEntity(dim6);

            LinearDimension dim7 = new LinearDimension(new Line(v25, v26), d8 * 5, -90, dimensionStyle);
            dim7.UserText = "d1=" + Math.Round(d1 * scale, 1);
            dxf.AddEntity(dim7);

            LinearDimension dim8 = new LinearDimension(new Line(v95, v109), d8, 0, dimensionStyle);
            dim8.UserText = "l4=" + Math.Round(l4 * scale, 1);
            dxf.AddEntity(dim8);

            LinearDimension dim9 = new LinearDimension(new Line(fun.Polar(v108, 90 * pi / 180, d8 / 2), fun.Polar(v108, -90 * pi / 180, d8 / 2)), d8 * 3, -90, dimensionStyle);
            dim9.UserText = "d8=" + Math.Round(d8 * scale, 1);
            dxf.AddEntity(dim9);

            fun.jdbz1(dxf, new Line(v44, fun.Polar(v44, 177.5 * pi / 180, 0.1)), new Line(v41, fun.Polar(v41, -177.5 * pi / 180, 0.1)), 620, "5°43'29''", 1);

            fun.gcbz(dxf, (fun.Polar(v41, -177.5 * pi / 180, 45)), 10, -90, 7, 180, 8, 1, 1, "A", "Φ0.005", 2, "czd", 1);

            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);
            Vector2 p0 = new Vector2(0, 0);
            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - 10 * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }


            //定义格式，路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);


        }

}
}
 